package com.situ.day39;

import org.junit.Test;

import java.lang.reflect.Method;
import java.util.Arrays;

//@Author("男")
//@Author(value = "男")
//@Author(value = {"男", "女"})
@Author(name = "zhao", age = 12, value = "男")
public class AuthorDemo {

    @Author
    private String str;

    @Author(name = "zhangsan", age = 23, value = {"男", "女"})
    //@Author(name = "zhangsan")
    public void add() {
    }

    @Test
    public void test1() throws NoSuchMethodException {
        Class<AuthorDemo> clazz = AuthorDemo.class;
        Author typeAuthor = clazz.getAnnotation(Author.class);
        System.out.println(typeAuthor.value()[0]);

        //1.先获得代表这个方法的Method
        Method method = clazz.getDeclaredMethod("add");
        //2.在Method上拿到指定注解
        Author methodAnnotation = method.getAnnotation(Author.class);
        System.out.println(methodAnnotation.name());//zhangsan
        System.out.println(methodAnnotation.age());//23
        System.out.println(Arrays.toString(methodAnnotation.value()));//[男, 女]
    }
}
